

from App.models.db_models import School, Targetlist
from App.models._models import close
from flask import Blueprint, jsonify, request

school = Blueprint('school', __name__, url_prefix="/school")


def Li(L):
    return L


@school.route('/', methods=['POST'])
def school_():

    case1 = request.json.get('case')
    curriculum = School.query.all()
    tar = Targetlist.query.all()

    close()

    def Tar(j):
        j = j-1
        a = {
            "id": tar[j].id,
            "name": tar[j].name
        }
        return a

    def Cur(i, L):
        i = i-1
        a = {
            "id": curriculum[i].id,
            "label": curriculum[i].label,
            "describe": curriculum[i].describe,
            "targetList": L
        }
        return a

    if case1 == 1:
        return jsonify(
            Cur(1, Li([Tar(1)])),
            Cur(2, Li([Tar(2)])),
            Cur(2, Li([Tar(3), Tar(4), Tar(5)])),
            Cur(3, Li([Tar(3), Tar(4), Tar(5), Tar(6), Tar(7), Tar(8)])),
            Cur(4, Li([Tar(9), Tar(10), Tar(11), Tar(12), Tar(
                13), Tar(14), Tar(15), Tar(16), Tar(17)])),
            Cur(5, Li([Tar(18), Tar(19), Tar(20), Tar(21), Tar(22), Tar(23)])),
            Cur(6, Li([Tar(24)]))
        )
    elif case1 == 2:
        return jsonify(
            Cur(1, Li([Tar(1)])),
            Cur(2, Li([Tar(2)])),
            Cur(2, Li([Tar(3), Tar(4), Tar(5)])),
            Cur(3, Li([Tar(3), Tar(4), Tar(5), Tar(6), Tar(7), Tar(8)])),
            Cur(4, Li([Tar(9), Tar(10), Tar(11), Tar(12), Tar(
                13), Tar(14), Tar(15), Tar(16), Tar(17)])),
            Cur(5, Li([Tar(18), Tar(19), Tar(20), Tar(21), Tar(22), Tar(23)])),
            Cur(6, Li([Tar(24)]))
        )
    elif case1 == 3:
        return jsonify(
            Cur(1, Li([Tar(1)])),
            Cur(2, Li([Tar(2)])),
            Cur(2, Li([Tar(3), Tar(4), Tar(5)])),
            Cur(3, Li([Tar(3), Tar(4), Tar(5), Tar(6), Tar(7), Tar(8)])),
            Cur(4, Li([Tar(9), Tar(10), Tar(11), Tar(12), Tar(
                13), Tar(14), Tar(15), Tar(16), Tar(17)])),
            Cur(5, Li([Tar(18), Tar(19), Tar(20), Tar(21), Tar(22), Tar(23)])),
            Cur(6, Li([Tar(24)]))
        )
    elif case1 == 4:
        return jsonify(
            Cur(1, Li([Tar(1)])),
            Cur(2, Li([Tar(2)])),
            Cur(2, Li([Tar(3), Tar(4), Tar(5)])),
            Cur(3, Li([Tar(3), Tar(4), Tar(5), Tar(6), Tar(7), Tar(8)])),
            Cur(4, Li([Tar(9), Tar(10), Tar(11), Tar(12), Tar(
                13), Tar(14), Tar(15), Tar(16), Tar(17)])),
            Cur(5, Li([Tar(18), Tar(19), Tar(20), Tar(21), Tar(22), Tar(23)])),
            Cur(6, Li([Tar(24)]))
        )
